package MathCore.Operands;

import MathCore.Lexeme;
import MathCore.Operand;
import MathCore.Real;
import MathCore.Real.NumberFormat;

public class Number extends Operand
{
	protected Real value;
	protected boolean editable = true;
	public static NumberFormat format;

	public int numbers_after_point = 0;

	public Number()
	{
		value = new Real(0);
	}

	public Number(int v)
	{
		value = new Real(v);
	}

	public Number(Real v)
	{
		if(v != null) value = new Real(v);
		else value = new Real(0);
	}

	public Number(Number v)
	{
		if(v != null)
		{
			value = new Real(v.get());
			numbers_after_point = v.numbers_after_point;
		}
		else value = new Real(0);
	}

	public Real get()
	{
		return value;
	}

	public String toString()
	{
		String result;
		if(format == null) 
		{
			format = new NumberFormat();
			format.maxwidth = 8;
			format.precision = 4;
		}
		result = value.toString(format);
		if(numbers_after_point == -1) result += '.';

		return result;
	}

	public Lexeme clone()
	{
		return new Number(this);
	}

	public boolean editable()
	{
		return editable;
	}
}
